package com.ddd.mill.infrastructure.persistent.repository.impl.producttype;

import com.ddd.mill.domain.aggregate.producttype.entity.ProductType;
import com.ddd.mill.domain.aggregate.producttype.repository.ProductTypeRepository;
import com.ddd.mill.infrastructure.persistent.dao.product.ProductTypeDao;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author liu
 * @title: ProductTypeMyBatisRepositoryImpl
 * @projectName trading-center
 * @date 2020/11/3010:25
 */
public class ProductTypeMyBatisRepositoryImpl implements ProductTypeRepository {
    @Resource
    ProductTypeDao dao;
    @Override
    public ProductType load(Long id) {
        return dao.selectById(id);
    }

    @Override
    public Long save(ProductType entity) {
        if (!Objects.isNull(entity.getId()) && !Objects.isNull(dao.selectById(entity.getId()))) {
            dao.updateById(entity);
        } else {
            dao.insert(entity);
        }
        return entity.getId();
    }

}
